﻿using System;
using System.IO;
using System.Collections.Generic;

namespace LoggerNamespace
{
    public class LoggerHtml: ILogger
    {
        private List<string> log;
        private ILogger log1;

        public LoggerHtml()
        {
            log = new List<string>();
            log.Add("<HTML>\n");
            log.Add("<\\HTML>");
        }
        public void AddMessage(string message)
        {
            log.RemoveAt(log.Count - 1);
            log.Add("<p>" + message + "</p>\n");
            log.Add("</HTML>");
        }

        public string ShowLog()
        {
            string result = "";
            foreach (string str in log)
            {
                result += str;
            }
            return result;
        }
        public void SaveLog()
        {
            string outLog;
            StreamWriter sw = new StreamWriter("log.txt");
            outLog = ShowLog();
            sw.Write(outLog);
            sw.Close();
        }
        public static implicit operator LoggerText(LoggerHtml logHtml)
        {
            string temp;
            string line;
            LoggerText logText = new LoggerText();
            for(int i = 1; i < (logHtml.log.Count - 1); i++)
            {
                line = logHtml.log[i];
                temp = line.Remove(0, 3);
                line = temp.Remove(temp.Length - 5, 5);
                logText.AddMessage(line);
            }
            return logText;
        }
    }
}
